Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

fix(utils): handle Web Locks API tab backgrounding in SSE multiplexer#9252

Open
tmdeveloper007 wants to merge 1 commit into
SandeepVashishtha:masterfrom
tmdeveloper007:#9247
Open

fix(utils): handle Web Locks API tab backgrounding in SSE multiplexer#9252
tmdeveloper007 wants to merge 1 commit into
SandeepVashishtha:masterfrom
tmdeveloper007:#9247

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary

The SSEClient in src/utils/sseMultiplexer.js used the Web Locks API for leader election. When a browser tab was backgrounded or suspended, the browser automatically released the Web Lock — but the internal releaseLockPromise was never called, causing the promise to hang indefinitely and leaving the tab in an inconsistent isLeader = false state.

Changes

  • Added a visibilitychange listener inside the Web Locks request callback to detect when the tab moves to background
  • When document.visibilityState === "hidden", the fix calls stopHeartbeatChecks(), sets isLeader = false, resolves releaseLockPromise, and transitions to localStorage-based election so another tab can claim leadership
  • Updated releaseLockPromise to also remove the visibilitychange listener on resolve, preventing memory leaks

Impact

Multi-tab SSE scenarios are now stable: backgrounded tabs properly release leadership, preventing heartbeat failures, duplicate SSE connections, and inconsistent subscriber state.

Closes #9247.

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@tmdeveloper007 is attempting to deploy a commit to the sandeepvashishtha's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the level:beginner 20pts label Jun 16, 2026
@github-actions github-actions Bot added gssoc:approved gssoc approved PR quality:clean 1.2x bug Something isn't working type:bug size/S Small pull request labels Jun 16, 2026

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our agent can fix these. Install it.

Gates Passed
4 Quality Gates Passed

Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@tmdeveloper007

Copy link
Copy Markdown
Contributor Author

@SandeepVashishtha Ready for review — PR #9252: fix SSE multiplexer Web Locks promise hanging when tab is backgrounded by adding visibilitychange listener and proper lock release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working gssoc:approved gssoc approved PR level:beginner 20pts quality:clean 1.2x size/S Small pull request type:bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(utils): handle Web Locks API tab backgrounding in SSE multiplexer

1 participant